#include<iostream>
#include<cstring>
using namespace std;
const int N = 210, M = N * N;
int h[N], ne[M], e[M], idx;
int n, m;
bool st[N];
int match[N];
void add(int a, int b)
{
	e[idx] = b;
	ne[idx] = h[a];
	h[a] = idx++;
}
bool dfs(int u)
{
	for (int i = h[u]; ~i; i = ne[i]) {
		int j = e[i];
		if (!st[j]) {
			st[j] = 1;
			if (!match[j] || dfs(match[j])) {
				match[j] = u;
				return 1;
			}
		}
	}
	return 0;
}
int main()
{
	cin >> n >> m;
	memset(h, -1, sizeof(h));
	for (int i = 1; i <= n; i++) {
		int s;
		cin >> s;
		while (s--) {
			int a;
			cin >> a;
			add(i, a);

		}
	}
	int ans = 0;
	// 	for(int i=1;i<=n;i++){
	// 	    for(int j=h[i];~j;j=ne[j]){
	// 	        cout<<e[j]<<" ";
	// 	   }
	// 	   cout<<endl;
	// 	}
	for (int i = 1; i <= n; i++) {
		memset(st, 0, sizeof(st));
		if (dfs(i))ans++;
	}
	cout << ans << endl;
	return 0;
}